package net.oschina.victor.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import net.oschina.victor.entity.User;
import net.oschina.victor.service.UserService;

//@CrossOrigin(maxAge = 3600)
@RestController
public class AuthController {
	@Autowired
	private UserService userService;

	@RequestMapping("/getUser")
	public User getUser() {
		User user = null;
		try {
			user = userService.findByUsername("aa");
			System.out.println(user.getName());
			// System.out.println(user.getRoles());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;
	}

	@RequestMapping(value = "authCode")
	@ResponseBody
	public String getMobileAuthCode(HttpServletRequest request, String callback) throws Exception {
		String result = "{'ret':'true'}";
		// 加上返回参数
		result = callback + "(" + result + ")";
		return result;
	}
}
